package micotime.com.amap_plugin.map.model;

import android.graphics.Color;
import android.util.AttributeSet;

import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapOptions;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.MyLocationStyle;

import java.util.Map;

public class UnifiedAMapOptions {
    public int getLogoPosition() {
        return logoPosition;
    }

    public void setLogonPosition(int logoPosition) {
        this.logoPosition = logoPosition;
    }

    public boolean iszOrderOnTop() {
        return zOrderOnTop;
    }

    public void setzOrderOnTop(boolean zOrderOnTop) {
        this.zOrderOnTop = zOrderOnTop;
    }

    public int getMapType() {
        return mapType;
    }

    public void setMapType(int mapType) {
        this.mapType = mapType;
    }

    public CameraPosition getCamera() {
        return camera;
    }

    public void setCamera(CameraPosition camera) {
        this.camera = camera;
    }

    public boolean isScaleControlsEnabled() {
        return scaleControlsEnabled;
    }

    public void setScaleControlsEnabled(boolean scaleControlsEnabled) {
        this.scaleControlsEnabled = scaleControlsEnabled;
    }

    public boolean isZoomControlsEnabled() {
        return zoomControlsEnabled;
    }

    public void setZoomControlsEnabled(boolean zoomControlsEnabled) {
        this.zoomControlsEnabled = zoomControlsEnabled;
    }

    public boolean isCompassEnabled() {
        return compassEnabled;
    }

    public void setCompassEnabled(boolean compassEnabled) {
        this.compassEnabled = compassEnabled;
    }

    public boolean isScrollGesturesEnabled() {
        return scrollGesturesEnabled;
    }

    public void setScrollGesturesEnabled(boolean scrollGesturesEnabled) {
        this.scrollGesturesEnabled = scrollGesturesEnabled;
    }

    public boolean isZoomGesturesEnabled() {
        return zoomGesturesEnabled;
    }

    public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) {
        this.zoomGesturesEnabled = zoomGesturesEnabled;
    }

    public boolean isTiltGesturesEnabled() {
        return tiltGesturesEnabled;
    }

    public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) {
        this.tiltGesturesEnabled = tiltGesturesEnabled;
    }

    public boolean isRotateGesturesEnabled() {
        return rotateGesturesEnabled;
    }

    public void setRotateGesturesEnabled(boolean rotateGesturesEnabled) {
        this.rotateGesturesEnabled = rotateGesturesEnabled;
    }

    /**
     * 高德地图”Logo的位置
     */
    private int logoPosition = AMapOptions.LOGO_POSITION_BOTTOM_LEFT;


    private boolean zOrderOnTop = false;

    /**
     * 地图模式
     */
    private int mapType = AMap.MAP_TYPE_NORMAL;

    /**
     * 地图初始化时的地图状态， 默认地图中心点为北京天安门，缩放级别为 10.0f
     */
    private CameraPosition camera = null;

    /**
     * 比例尺功能是否可用
     */
    private boolean scaleControlsEnabled = false;

    /**
     * 地图是否允许缩放
     */
    private boolean zoomControlsEnabled = true;

    /**
     * 指南针是否可用
     */
    private boolean compassEnabled = false;

    /**
     * 拖动手势是否可用
     */
    private boolean scrollGesturesEnabled = true;

    /**
     * 缩放手势是否可用
     */
    private boolean zoomGesturesEnabled = true;

    /**
     * 地图倾斜手势（显示3D效果）是否可用
     */
    private boolean tiltGesturesEnabled = true;

    /**
     * 地图旋转手势是否可用
     */
    private boolean rotateGesturesEnabled = true;

    /**
     * 是否启用我的定位按钮
     */
    private boolean myLocationButtonEnabled = true;

    /**
     * 显示我的位置按钮
     */
    private boolean showMyLocation = false;

    private int locationType = 1;

    /**
     * 设置是否打开定位图层（myLocationOverlay）。
     */
    private boolean isMyLocationEnabled = false;

    public MyLocationStyle getMyLocationStyle() {
        return myLocationStyle;
    }

    public void setMyLocationStyle(MyLocationStyle myLocationStyle) {
        this.myLocationStyle = myLocationStyle;
    }

    private MyLocationStyle myLocationStyle = new MyLocationStyle();

    /**
     * @param logonPosition         高德地图”Logo的位置
     * @param zOrderOnTop
     * @param mapType               地图模式
     * @param camera                地图初始化时的地图状态， 默认地图中心点为北京天安门，缩放级别为 10.0f
     * @param scaleControlsEnabled  比例尺功能是否可用
     * @param zoomControlsEnabled   地图是否允许缩放
     * @param compassEnabled        指南针是否可用
     * @param scrollGesturesEnabled 拖动手势是否可用
     * @param zoomGesturesEnabled   缩放手势是否可用
     * @param tiltGesturesEnabled   地图倾斜手势（显示3D效果）是否可用
     * @param rotateGesturesEnabled 地图旋转手势是否可用
     */
    public UnifiedAMapOptions(
            int logonPosition,
            boolean zOrderOnTop,
            int mapType,
            CameraPosition camera,
            boolean scaleControlsEnabled,
            boolean zoomControlsEnabled,
            boolean compassEnabled,
            boolean scrollGesturesEnabled,
            boolean zoomGesturesEnabled,
            boolean tiltGesturesEnabled,
            boolean rotateGesturesEnabled,
            boolean myLocationButtonEnabled,
            boolean showMyLocation,
            boolean isMyLocationEnabled,
            int locationType) {
        this.logoPosition = logonPosition;
        this.zOrderOnTop = zOrderOnTop;
        this.mapType = mapType;
        this.camera = camera;
        this.scaleControlsEnabled = scaleControlsEnabled;
        this.zoomControlsEnabled = zoomControlsEnabled;
        this.compassEnabled = compassEnabled;
        this.scrollGesturesEnabled = scrollGesturesEnabled;
        this.zoomGesturesEnabled = zoomGesturesEnabled;
        this.tiltGesturesEnabled = tiltGesturesEnabled;
        this.rotateGesturesEnabled = rotateGesturesEnabled;
        this.myLocationButtonEnabled = myLocationButtonEnabled;
        this.showMyLocation = showMyLocation;
        this.isMyLocationEnabled = isMyLocationEnabled;
        this.locationType = locationType;
    }

    public UnifiedAMapOptions(Map<String, Object> params) {
        if (params == null) return;
        if (params.get("logonPosition") != null) {
            this.logoPosition = Integer.parseInt(params.get("logonPosition").toString());
        }
        if (params.get("zOrderOnTop") != null) {
            this.zOrderOnTop = Boolean.parseBoolean(params.get("zOrderOnTop").toString());
        }
        if (params.get("mapType") != null) {
            this.mapType = Integer.parseInt(params.get("mapType").toString());
        }
        if (params.get("scaleControlsEnabled") != null) {
            this.scaleControlsEnabled = Boolean.parseBoolean(params.get("scaleControlsEnabled").toString());
        }
        if (params.get("zoomControlsEnabled") != null) {
            this.zoomControlsEnabled = Boolean.parseBoolean(params.get("zoomControlsEnabled").toString());
        }
        if (params.get("compassEnabled") != null) {
            this.compassEnabled = Boolean.parseBoolean(params.get("compassEnabled").toString());
        }
        if (params.get("scrollGesturesEnabled") != null) {
            this.scrollGesturesEnabled = Boolean.parseBoolean(params.get("scrollGesturesEnabled").toString());
        }
        if (params.get("zoomGesturesEnabled") != null) {
            this.zoomGesturesEnabled = Boolean.parseBoolean(params.get("zoomGesturesEnabled").toString());
        }
        if (params.get("myLocationButtonEnabled") != null) {
            this.myLocationButtonEnabled = Boolean.parseBoolean(params.get("myLocationButtonEnabled").toString());
        }
        if (params.get("showMyLocation") != null) {
            this.showMyLocation = Boolean.parseBoolean(params.get("showMyLocation").toString());
        }
        if (params.get("isMyLocationEnabled") != null) {
            this.isMyLocationEnabled = Boolean.parseBoolean(params.get("isMyLocationEnabled").toString());
        }
        if (params.get("myLocationStyle_strokeColor") != null) {
            this.myLocationStyle.strokeColor(Color.parseColor(params.get("myLocationStyle_strokeColor").toString()));
        }
        if (params.get("myLocationStyle_strokeWidth") != null) {
            this.myLocationStyle.strokeWidth(Float.parseFloat(params.get("myLocationStyle_strokeWidth").toString()));
        }
        if (params.get("myLocationStyle_radiusFillColor") != null) {
            this.myLocationStyle.radiusFillColor(Color.parseColor(params.get("myLocationStyle_radiusFillColor").toString()));
        }
        if (params.get("locationType") != null) {
            this.locationType = (int) params.get("locationType");
        }
        /*
        //TODO 实现
        this.camera = camera;

        this.tiltGesturesEnabled = tiltGesturesEnabled;
        this.rotateGesturesEnabled = rotateGesturesEnabled;
         */
    }

    public AMapOptions getOptions() {
        AMapOptions aMapOptions = new AMapOptions();
        aMapOptions.camera(this.camera);
        aMapOptions.logoPosition(this.logoPosition);
        aMapOptions.zOrderOnTop(this.zOrderOnTop);
        aMapOptions.mapType(this.mapType);
        aMapOptions.scaleControlsEnabled(this.scaleControlsEnabled);
        aMapOptions.zoomControlsEnabled(this.zoomControlsEnabled);
        aMapOptions.compassEnabled(this.compassEnabled);
        aMapOptions.scrollGesturesEnabled(this.scrollGesturesEnabled);
        aMapOptions.zoomGesturesEnabled(this.zoomGesturesEnabled);
        //aMapOptions.camera;
        return aMapOptions;
    }

    static public UnifiedAMapOptions createWithMap(Map<String, Object> params) {
        UnifiedAMapOptions unifiedAMapOptions = new UnifiedAMapOptions(params);
        return unifiedAMapOptions;
    }

    public boolean isMyLocationButtonEnabled() {
        return myLocationButtonEnabled;
    }

    public void setMyLocationButtonEnabled(boolean myLocationButtonEnabled) {
        this.myLocationButtonEnabled = myLocationButtonEnabled;
    }

    public boolean isShowMyLocation() {
        return showMyLocation;
    }

    public void setShowMyLocation(boolean showMyLocation) {
        this.showMyLocation = showMyLocation;
    }

    public boolean isMyLocationEnabled() {
        return isMyLocationEnabled;
    }

    public void setMyLocationEnabled(boolean myLocationEnabled) {
        isMyLocationEnabled = myLocationEnabled;
    }

    public int getLocationType() {
        return locationType;
    }

    public void setLocationType(int locationType) {
        this.locationType = locationType;
    }
}
